package com.example.springioc.config;

import com.example.springioc.entity.User;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

@Component
public class BeanConfig {
//    注意:在 Spring 框架的设计中，方法注解@Bean 要配合类注解才能将对象正常的存储到 Spring 容器中
//    @Bean
//    public User user() {
//        User user = new User();
//        user.setName("qinglin");
//        user.setAge(21);
//        return user;
//    }

    @Bean(name = {"u1", "user1"})
    public User user1() {
        User user = new User();
        user.setName("qinglin");
        user.setAge(22);
        return user;
    }

//    @Primary //指定该bean为默认bean的实现
    @Bean("u2")
    public User User2() {
        User user = new User();
        user.setName("qinglin");
        user.setAge(23);
        return user;
    }
}
